using ImageCSharp.Core.Services;
using ImageCSharp.Core.Models;
using Xunit;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;

namespace ImageCSharp.Tests
{
    public class ImageServiceTests
    {
        [Fact]
        public void CreateNewDocument_ShouldInitializeWithDefaultSize()
        {
            // Arrange & Act
            var document = new ImageDocument();

            // Assert
            Assert.NotNull(document.Image);
            Assert.Equal(800, document.Image.Width);
            Assert.Equal(600, document.Image.Height);
            Assert.Equal("Untitled", document.Name);
            Assert.False(document.IsModified);
        }

        [Fact]
        public void ResizeImage_ShouldChangeDimensions()
        {
            // Arrange
            var service = new ImageService();
            var document = new ImageDocument();
            var originalWidth = document.Image.Width;
            var originalHeight = document.Image.Height;

            // Act
            service.ResizeImage(document, 400, 300);

            // Assert
            Assert.Equal(400, document.Image.Width);
            Assert.Equal(300, document.Image.Height);
            Assert.True(document.IsModified);
        }

        [Fact]
        public void GetStatistics_ShouldReturnValidData()
        {
            // Arrange
            var service = new ImageService();
            var document = new ImageDocument();

            // Act
            var stats = service.GetStatistics(document);

            // Assert
            Assert.NotNull(stats);
            Assert.Equal(800, stats.Width);
            Assert.Equal(600, stats.Height);
            Assert.True(stats.MeanBrightness >= 0 && stats.MeanBrightness <= 1);
            Assert.NotNull(stats.ColorDistribution);
        }
    }
}